package com.tn.shirojwt.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * @description:
 * @author: tn
 * @time: 2020/3/16 22:02
 */
public class StringUtils {



    /**
     * 获得本次输入的密码的密文
     * @param password
     * @param salt 用户名+盐
     * @return
     */
    public static String getInputPasswordCiph(String password, String salt)
    {
        if(salt == null)
        {
            password = "";
        }
        //生成的密文
        String ciphertext = new Md5Hash(password,salt,2).toString();

        return ciphertext;
    }

    /**
     * 生成盐值
     * @return
     */
    public static String getSalt()
    {
       try {
           //生成盐值
           return new SecureRandomNumberGenerator().nextBytes().toHex();
       }catch (Exception e){
           e.printStackTrace();
       }

        return null;
    }


    public static void main(String[] args) {
        System.err.println(getInputPasswordCiph("123456","test8d78869f470951332959580424d4bf4f"));
        System.err.println(getSalt());
    }
}
